Setup:

library(tidyverse)
library(sf)
library(tmap)
library(obsplot)
library(plotly)
library(gt)

Análise de “accidents”

load(here::here("data/accidents.rda"))

Transformando em um arquivo espacial

accidents_sf <- accidents |>
  st_as_sf(wkt = "Location")

Plotando apenas uma parte da base para ver os acidentes

accidents_slice <- accidents_sf |>
  slice_sample(prop = 0.01)

tmap_mode("view")

tm_shape(accidents_slice) + 
  tm_dots(size = 0.05, alpha = 0.7, col = obs_palette$blue)

Fazendo uma serie temporal dos acidentes

theme_set(theme_obs())


plot <- accidents |> 
  mutate(Date = mdy(Date), mes = floor_date(Date, "month")) |> 
  count(mes) |> 
  ggplot(aes(x = mes, y = n)) +
  geom_col(fill = obs_palette$blue) +
  scale_y_continuous(limits = c(0, NA))
  
ggplotly(plot)

Análise de “alerts”

load(here::here("data/alerts.rda"))

Visualisando os alertas marcados como JAM:

alerts_sf <- alerts |> st_as_sf(wkt = "Location")

alerts_jam_sample <- alerts_sf |> 
  filter(Type == "JAM") |> 
  slice_sample(prop = 0.01)

tm_shape(alerts_jam_sample) + 
  tm_dots(size = 0.05, alpha = 0.7, col = obs_palette$red)

Análise de “irregularities”

load(here::here("data/irregularities.rda"))

irr_grouped <- irregularities |> 
  janitor::clean_names() |> 
  group_by(street) |> 
  summarise(
    avg_length = mean(avg_length_meters),
    avg_delay = mean(avg_delay_seconds),
    avg_impacted_wazers = mean(impacted_wazers)
  )

irr_grouped |> 
  select(street, avg_length, avg_delay, avg_impacted_wazers) |> 
  gt() |> 
  opt_interactive()